package com.example.littleken.secret;

import android.content.Context;
import android.content.SharedPreferences.Editor;

/**本类主要存放配置信息，各种静态变量与获取本机信息的方法
 * Created by littleken on 2018/4/24.
 */

public class Config {

    //网络通信状态码
    public static final int RESULT_STATUS_SUCCESS = 1;//成功
    public static final int RESULT_STATUS_FAIL = 0;//失败
    public static final int RESULT_STATUS_INVALID_TOKEN = 2;//token过期

    //网络通信key
    public static final String KET_STAUS = "status";
    public static final String KEY_PHONE_NUM = "phone";
    public static final String KEY_PHONE_MD5 = "phone_md5";
    public static final String KEY_ACTION = "action";
    public static final String ACTION_GET_CODE = "send_pass";
    public static final String ACTION_LOGIN = "login";
    public static final String KEY_CODE= "code";
    public static final String ACTION_UPLOAD_CONTACTS= "upload_contacts";
    public static final String KEY_CONTACTS= "contacts";
    public static final String ACTION_TIMELINE= "timeline";
    public static final String KEY_PAGE= "page";
    public static final String KEY_PERPAGE= "perpage";
    public static final String KEY_TIMELINE= "timeline";
    public static final String KEY_MSG_ID = "msgId";
    public static final String KEY_MSG = "msg";
    public static final String ACTION_GET_COMMENT = "get_comment";
    public static final String KEY_COMMENTS = "comments";
    public static final String KEY_CONTENT = "content";
    public static final String ACTION_PUBCOMMENT = "pub_comment";
    public static final String ACTION_PUBLISH = "publish";
    public static final String KEY_TOKEN = "token";
    //服务器地址
    //public static final String SERVER_URL = "http://demo.eoeschool.com/api/v1/nimings/io";
    //测试用serverurl
    public static final String SERVER_URL = "http://192.168.31.46:8080/Apptextserver/api.jsp";
    public static final String APP_ID = "com.littleken.Secret";
    //编码方式
    public static final String CHARSET = "utf-8";
    //activity跳转请求码
    public static final int REQUESTCODE = 555;
    public static final  int ACTIVITY_NEED_RESULT_NEED_REFRESH = 666;

    /**
     * 获取到本地缓存Token
     * @param context 上下文
     * @return String Token
     */
    public static String getCachedToken(Context context){

        //SharedPreferences在android中主要以xml文件的方式保存较小的键值对。
        return context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).getString(KEY_TOKEN,null);
    }
    /**
     * 在本地缓存Token
     * @param context 上下文
     * @param token Token
     */
    public static void cacheToekn(Context context,String token){
        Editor e = context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).edit();
        e.putString(KEY_TOKEN, token);
        e.commit();
    }

    /**
     * 获取本机手机号码
     * @param context 上下文
     * @return String 本机手机号码
     */
    public static String getCachePhoneNum(Context context){
        return context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).getString(KEY_PHONE_NUM,null);
    }

    /**
     * 存储手机号码
     * @param context 上下文
     * @param phoneNum String 本机手机号码
     */
    public static void cachePhoneNum(Context context,String phoneNum){
        Editor e = context.getSharedPreferences(APP_ID,Context.MODE_PRIVATE).edit();
        e.putString(KEY_PHONE_NUM,phoneNum);
        e.commit();
    }
}
